package com.niit.session20;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class StudentDao {
	public static void main(String[] args) {
		Connection conn = JDBCUtils.getConn();
		try {
			Statement statement = conn.createStatement();
//			故意打错了表名字，让JDBC抛出异常
			ResultSet rs = statement.executeQuery("SELECT * FROM students where batch = 3;");
			while (rs.next()) {
				System.out.println(rs.getString("sid")+"---"+rs.getString("name"));
			}
		} catch (SQLException e) {
//			如果不想看红色的堆栈信息，可以注释掉这行代码
//			e.printStackTrace();
//			打印错误消息
			System.out.println("错误消息："+e.getMessage());
//			打印错误码
			System.out.println("错误码："+e.getErrorCode());
		}
	}

}
